﻿using AutoMapper;
using MediatR;
using S_Gridding.Api.Application.Commands.Gridding;
using S_Gridding.Domains.FoundGridding;
using S_Gridding.Infrastructure.Interface.IWrite;
using S_Userinfor.Domains;

namespace S_Gridding.Api.Application.CommandsHanders.GriddingHanders
{
    public class GriddingCreateCommandsHanders : IRequestHandler<GriddingCreateCommands, int>
    {
        private readonly IGriddingRepository _sGridding;
        private readonly IMapper _mapper;

        public GriddingCreateCommandsHanders(IGriddingRepository sGridding, IMapper mapper)
        {
            _sGridding = sGridding;
            _mapper = mapper;
        }

        public async Task<int> Handle(GriddingCreateCommands request, CancellationToken cancellationToken)
        {
            var res = _mapper.Map<Gridding>(request);
            return await _sGridding.AddAsync(res);
        }
    }
}
